package parts4.lesson39;

/**
 * 负责数据保存
 * 给Data对象加上同步
 */
public class Data {
    private String title;
    private String note;

    public synchronized void get() {
        try {
            Thread.sleep(400);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(this.title + "=" + this.note);
    }

    public synchronized void set(String title, String note) {
        this.title = title;
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        this.note = note;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }
}
